package com.shizhanzhe.zxbapp.my;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.TiBean;
import com.shizhanzhe.zxbapp.utils.Util;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by YJ on 2018/10/23.
 */
public class TiRecordAdapter extends RecyclerView.Adapter<TiRecordAdapter.ViewHolder> {

    private Context context;
    private List<TiBean.DataBean> mData = new ArrayList<>();

    public TiRecordAdapter(Context context) {
        this.context = context;
    }

    public void updateData(List<TiBean.DataBean> dataSet){
        if (dataSet != null && !dataSet.isEmpty()){
            mData.addAll(dataSet);
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_ti_record, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TiBean.DataBean dataBean = mData.get(position);
        holder.tvContent.setText("提现金额: " + dataBean.getAcount() + "元");
        holder.tvTime.setText(Util.stampToDate(dataBean.getAddtime()+""));
        String states = "";
        //1已处理  0 未处理   2拒绝
        switch (dataBean.getStatus()){
            case 1:
                states = "已完成";
                break;
            case 0:
                states = "打款中";
                break;
            case 2:
                states = "提现失败";
                holder.tvReason.setVisibility(View.VISIBLE);
                holder.tvReason.setText("原因:"+dataBean.getScon());
                break;
        }
        holder.tvState.setText(states);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvContent;
        TextView tvTime;
        TextView tvReason;
        TextView tvState;
        public ViewHolder(View itemView) {
            super(itemView);
            //ButterKnife.bind(itemView);
            tvContent = itemView.findViewById(R.id.tv_content);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvState = itemView.findViewById(R.id.tv_state);
            tvReason=itemView.findViewById(R.id.tv_reason);
        }
    }
}
